﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="exambystep.aspx.cs" Inherits="Student_exambystep" %>
<!doctype html>
<html>
<head id="Head1" runat="server">
<meta http-equiv="x-ua-compatible" content="ie=7" />
<link type='text/css' href='../css/style.css' rel='stylesheet' media='screen' />
<link href="../css/exambystep.css" rel="stylesheet" type="text/css" />
<style>
.question{display:none;}
.questionlist{font-size:12px;}
#page{font-size:14px;}
#page span{font-size:14px;cursor:pointer;}
label{margin-left:5px;}
.en-opts{margin-left:32px;}
.cn-opts{margin-left:32px;font-size:12px;}
</style>
<script type="text/javascript" src="../js/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../js/jquery/jquery.cookie.js"></script>
<script type="text/javascript" src="../js/shielding.js"></script>
<script language="javascript" type="text/javascript">
    function TrunToChina(num) {
        //alert("你输入的是：" + num +"\r\n"+ "转换成数字后为：" + Chinese(num));
        return Chinese(num);
    }
    function Chinese(num) {
        if (!/^\d*(\.\d*)?$/.test(num)) {
            alert("<%=Resources.labels.not_number%>");
            return false;
        }
        var AA = new Array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九");
        var BB = new Array("", "十", "百", "千", "万", "亿", "点", "");
        var a = ("" + num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
        for (var i = a[0].length - 1; i >= 0; i--) {
            switch (k) {
                case 0:
                    re = BB[7] + re;
                    break;
                case 4:
                    if (!new RegExp("0{4}\\d{" + (a[0].length - i - 1) + "}$").test(a[0]))
                        re = BB[4] + re;
                    break;
                case 8:
                    re = BB[5] + re;
                    BB[7] = BB[5];
                    k = 0;
                    break;
            }
            if (k % 4 == 2 && a[0].charAt(i) == "0" && a[0].charAt(i + 2) != "0") re = AA[0] + re;
            if (a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k % 4] + re;
            k++;
        }
        if (a.length > 1) {
            re += BB[6];
            for (var i = 0; i < a[1].length; i++) re += AA[a[1].charAt(i)];
        }
        return re;
    }
</script>
<script type="text/javascript">
var isAnswer = [];

$(function () {
    setcontent();
    countTime();
    $(".currentquestion").show();
    $(".btn").mouseover(function () { $(this).css("color", "#FF0000"); }).mouseout(function () { $(this).css("color", "#555"); });
    
});
window.onresize = function () { setcontent(); };
//设置页面布局
function setcontent(){
    var obj = $("#content");
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    $(obj).css({
        "width": windowWidth - 240,
        "height": windowHeight - 100 - 64,
        "float": "left"
    });
}

var timeLeft = <%=model.PaperTime%> * 60 * 1000;
function countTime() {
    if (timeLeft == 0) {
        Submite();
        alert("<%=Resources.labels.timeend%>");
        return;
    }
    var startMinutes = parseInt(timeLeft / (60 * 1000), 10);
    var startSec = parseInt((timeLeft - startMinutes * 60 * 1000) / 1000)
    var sy =startMinutes + " <%=Resources.labels.Minute%> " + startSec + " <%=Resources.labels.Second%> ";
    $("#countdown").html(sy);
    timeLeft = timeLeft - 1000;
    setTimeout('countTime() ', 1000);
}
function isExitsId(_id){
    var tag = false;
    for(var i = 0; i < isAnswer.length; i++){
        if(_id == isAnswer[i]){
            tag = true;
        }
    }
    return tag;
} 
var currentid=0;//当前回答试题ID

function Sel(_id) {
    currentid = _id;
    var obj = $("#question_" + _id);
    if(!isExitsId(_id)){
        isAnswer.push(_id);
    }
    $("#status").html(isAnswer.length);
}

function hiditemlist(){
    $(".question").hide();
}
function Prev(){
    if(currentid==0){alert("<%=Resources.labels.first_question_must%>");return false;}
    var p = $("#question_"+currentid).prev();
    if(p.html()==null){alert("<%=Resources.labels.itisfirstquestion%>"); return false;}
    hiditemlist();
    currentid = p.attr("tip");
    p.show();
}
function Next(){
    if(currentid==0){alert("<%=Resources.labels.first_question_must%>");return false;}
    var n = $("#question_"+currentid).next();
    if(n.html()==null){alert("<%=Resources.labels.itisendquestion%>"); return false;}
    
    hiditemlist();
    currentid = n.attr("tip");
    n.show();
}

document.onkeydown = KeyDown;//屏蔽鼠标 F5等
</script>
    <title><%=model.PaperName %></title>
</head>
<body>
    <form id="form1" runat="server">

    <div class="banner"><div class="banner_right"></div></div>
    <div class="topbar"><h1><%=model.PaperName %></h1></div>

    <div class="main">
    
    <div id="content">
    <div  class="questionlist">
    <% int p = 0; %>
    <% for (int i = 0; i < model.ExamQuestionTypeList.Count; i++) { %>
    
        <% System.Collections.Generic.List<Exam.Core.Model.ExamQuestion> objQuestions = model.ExamQuestionTypeList[i].QuestionList;
           //乱序
           
            for (int k = 0; k < objQuestions.Count; k++) { %>

            <div class="question <% if(p==0){ Response.Write("currentquestion");} %>" id="question_<%=objQuestions[k].QuestionId.Trim()%>" tip="<%=objQuestions[k].QuestionId.Trim()%>" position="">
                <div class="questioncontent">
                <span style="margin-top:1px;color:#005500;"><%=getNumber(p+1) %>、</span> 
                <%=Server.HtmlDecode(objQuestions[k].QuestionContent.Trim())%></div>
                <div class="questionanswer">
                    <%if (model.ExamQuestionTypeList[i].QuestionTypeAttr.Trim() == "0") {%>
                    
                    <%if (objQuestions[k].QuestionType.Trim()=="1") {%><!--单选-->
                        <div class="optsContent">
                        <%System.Collections.Generic.List<Exam.Core.Model.ExamOpts> objOpts = objQuestions[k].ExamOptsList;
                        for (int m = 0; m < objOpts.Count; m++) { %>
                            <!--题型_试题ID-->
                            <div style="margin-bottom:10px;">
                            <input id="Rad_<%=objOpts[m].QuestionId.Trim() %>_<%=objOpts[m].QuestionOptsID %>" name="1_<%=objOpts[m].QuestionId.Trim() %>" type="radio" value="<%=objOpts[m].QuestionOptsValue.Trim()%>" onclick="return Sel('<%=objOpts[m].QuestionId.Trim() %>')" />
                            <label for="Rad_<%=objOpts[m].QuestionId.Trim() %>_<%=objOpts[m].QuestionOptsID %>">
                            <%=objOpts[m].QuestionOptsValue.Trim()%> 
                            <%=Server.HtmlDecode(objOpts[m].QuestionOptsText.Trim())%></label>
                            </div>
                        <%} %>
                        </div>
                    <%} %>
                    <%else if (objQuestions[k].QuestionType.Trim()=="2") {%><!--多选-->
                        <div class="optsContent">
                        <%System.Collections.Generic.List<Exam.Core.Model.ExamOpts> objOpts = objQuestions[k].ExamOptsList;
                        for (int m = 0; m < objOpts.Count; m++) { %>
                            <div style="margin-bottom:10px;">
                            <input id="Rad_<%=objOpts[m].QuestionId.Trim() %>_<%=objOpts[m].QuestionOptsID %>" name="2_<%=objOpts[m].QuestionId.Trim() %>" type="checkbox" value="<%=objOpts[m].QuestionOptsValue.Trim()%>" onclick="return Sel('<%=objOpts[m].QuestionId.Trim() %>')" />
                            <label for="Rad_<%=objOpts[m].QuestionId.Trim() %>_<%=objOpts[m].QuestionOptsID %>"><%=objOpts[m].QuestionOptsValue.Trim()%> <%=Server.HtmlDecode(objOpts[m].QuestionOptsText.Trim())%></label>
                            </div>
                        <%} %>
                        </div>
                    <%} %>
                    <%else if (objQuestions[k].QuestionType.Trim()=="3") {%><!--判断-->

                            <input id="Rad_3_1_<%=objQuestions[k].QuestionId.Trim() %>" name="3_<%=objQuestions[k].QuestionId.Trim() %>" type="radio" value="A"  onclick="return Sel('<%=objQuestions[k].QuestionId.Trim() %>')" />
                            <label for="Rad_3_1_<%=objQuestions[k].QuestionId.Trim() %>"><%=Resources.labels.right%></label>
                            <br />
                            <input id="Rad_3_2_<%=objQuestions[k].QuestionId.Trim() %>" name="3_<%=objQuestions[k].QuestionId.Trim() %>" type="radio" value="B" onclick="return Sel('<%=objQuestions[k].QuestionId.Trim() %>')" />
                            <label for="Rad_3_2_<%=objQuestions[k].QuestionId.Trim() %>"><%=Resources.labels.error%></label>

                    <%} %>
                    
                        
                        
                    <%}
                      else { %>
                        <div class="answerContent"><textarea id="txt_<%=objQuestions[k].QuestionType %>_<%=objQuestions[k].QuestionId.Trim() %>" name="<%=objQuestions[k].QuestionType %>_<%=objQuestions[k].QuestionId.Trim() %>" style="width:410px;height:40px;"  onclick="return Sel('<%=objQuestions[k].QuestionId.Trim() %>')" ></textarea></div>
                    <%} %>
                </div>
            </div>
        <% p++;
            } %>
    
    <%} %>
    </div>

    <div id="page" style="padding:25px;">
        <input id="Button2" type="button" class="button" value="<%=Resources.labels.PrevQuestion%>"  onclick="Prev()"/>
        <input id="Button3" type="button" class="button" value="<%=Resources.labels.NextQuestion%>"  onclick="Next()"/>
     </div>

    </div>
    
    <div id="right">
        <%=Resources.labels.warning%>：<br />
        <div class="rightqtype">
            <ul>
            <% for (int i = 0; i < model.ExamQuestionTypeList.Count; i++) { %>
            <li><%=model.ExamQuestionTypeList[i].QuestionTypeTitle.Trim()%></li>
            <%} %>
            </ul>
        </div>

        <div style="margin-bottom:7px;margin-top:7px;">
            <span style="font-size:14px; font-weight:bold;display:block;"><%=Resources.labels.ExamTime%>：</span>
            <span style="font-size:12px; font-weight:normal;display:block;"><%=model.PaperTime%><%=Resources.labels.Minute%></span></div>

        <div style="margin-bottom:7px;">
            <span style="font-size:14px; font-weight:bold;display:block;"><%=Resources.labels.StarTime%>：</span>
            <span style="font-size:12px; font-weight:normal;display:block;"><%=DateTime.Now%></span>
        </div>

        <div style="margin-bottom:7px;">
            <span style="font-size:14px; font-weight:bold;display:block;"><%=Resources.labels.SurplusTime%>：</span>
        </div>

        <div id="countdown" style="font-size:12px; font-weight:normal;margin-bottom:7px;"></div>

        <div style="margin-bottom:7px;font-size:12px; font-weight:normal;"><%= String.Format(Resources.labels.questionNumberpoint, qnumber)%></div>
        <div style="margin-bottom:7px;font-size:12px; font-weight:normal;"><%= String.Format(Resources.labels.havedanswer, "<span id=\"status\">0</span>")%></div>

        <div>
            <input id="Button1" type="button" class="button" value="<%=Resources.labels.Submit%>" onclick="SubmiteExam()" /></div>
        <div id="subStatus"></div>
    </div>
    
    </div>
    <br class="clear" />
    
    <div id="footer"></div>
    
    </form>
<script>
    function SubmiteExam() {
        if (confirm("<%=Resources.labels.ConfirmSubmite%>")) {
            Submite();
        }
    }
    function Submite() {
        //获取试题ID和考生答案
        //获取试题ID和考生答案
        //表单
        var sbtype = "<%=sbtype.ToString().Trim('|') %>"; //题型
        var typelist = sbtype.split("|");
        var list = "<%=sb.ToString().Trim('|') %>"; //题型_题目编号
        var qlist = list.split("|");
        var frm = "{";
        frm += "\"paper\":[";
        for (var m = 0; m < qlist.length; m++) {//循环题型

            frm += "{";
            frm += "\"" + typelist[m] + "\":{";
            var frmList = qlist[m].split(",");
            for (var a = 0; a < frmList.length; a++) {//循环题型下试题
                var inputName = frmList[a];
                var inputValue = "";
                if (inputName.split("_")[0] == "1") {//单选按钮
                    inputValue = $("input[name=" + inputName + "][checked]").val();
                } else if (inputName.split("_")[0] == "2") {//多选按钮
                    $("input[name=" + inputName + "][checked]").each(function () { //由于复选框一般选中的是多个,所以可以循环输出
                        inputValue += $(this).val();
                    }); 

                    //inputValue = $("input[name=" + inputName + "][checked]").val();
                } else if (inputName.split("_")[0] == "3") {//判断按钮
                    inputValue = $("input[name=" + inputName + "][checked]").val();
                    //if (inputValue.toUpperCase() == "TRUE") { inputValue = "A"; } else {inputValue = "B";}
                } else {
                    inputValue = $("input[name=" + inputName + "]").val();
                    
                }
                if (inputValue == undefined) {//未选答案 设置为空字符串
                    inputValue = "";
                }

                frm += '"' + inputName + '"' + ":" + '"' + inputValue + '"' + ",";
            }
            frm = frm.substring(0, frm.length - 1);

            frm += "}},";
        }
        frm = frm.substring(0, frm.length - 1);

        frm += "],\"paperid\":\"<%=id %>\","; //试卷ID
        frm += "\"myid\":\"<%=isTheMe.StudentID %>\","; //考生ID
        frm += "\"paperfilepath\":\"<%=paperfilepath.Trim() %>\","; //考卷路径
        frm += "\"typelist\":\"<%=sbtype.ToString().Trim() %>\","; //题型列表
        frm += "\"SEId\":\"<%=SEId %>\""; //考生考卷表
        //
        frm += "}";
        //alert(frm);
        //return false;

        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/exam.aspx",
            data: frm, //eval("(" + frm + ")"),
            //dataType: "json",
            //contentType: 'application/json; charset=utf8',
            beforeSend: function () {
                $("#subStatus").html("<img src='../images/loading16x16.gif' border=0 /> <%=Resources.labels.PleaseWaiting%>");
            },
            success: function (msg) {
                if (msg == "1") {
                    alert("<%=Resources.labels.paper_submit%>");
                    $("#subStatus").html("<img src='../images/ok.gif' border=0 /> <%=Resources.labels.Submit_OK%>");
                    //设置按钮为不可再次提交状态
                    $("#Button1").attr("disabled", "false");
                } else {
                    //alert("失败！请重新");
                    $("#subStatus").html("<img src='../images/erro.gif' border=0 /> <%=Resources.labels.Submit_Fail%>");
                }
            },
            error: function (msg) {
                //alert("失败！请重新");
                $("#subStatus").html("<img src='../images/erro.gif' border=0 /> <%=Resources.labels.Submit_Err%>");
            }
        });
    }
</script>    
</body>
</html>